package com.shujia.spark

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.rdd.RDD

object Demo13Sort {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()
      .setMaster("local")
      .setAppName("map")


    val sc = new SparkContext(conf)


    val ageRDD: RDD[(String, Int)] = sc.parallelize(List(("001", 231), ("002", 24), ("003", 25)))

    /**
      * sortBy: 指定一个排序的列, 默认是升序
      * sortByKey : 通过key进行排序
      *
      */

    val sortRDD: RDD[(String, Int)] = ageRDD.sortBy(kv => kv._2, ascending = false)

    sortRDD.foreach(println)


  }
}
